# Maintainer: Christoph Reiter <reiter.christoph@gmail.com>

_realname=setuptools-scm
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
provides=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
replaces=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=5.0.1
pkgrel=5
pkgdesc='Handles managing your python package versions in scm metadata (mingw-w64)'
url='https://github.com/pypa/setuptools_scm'
license=('MIT')
arch=('any')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-setuptools"
         "${MINGW_PACKAGE_PREFIX}-python-toml")
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname/-/_}-${pkgver}.tar.gz"
        "0001-git-Use-show-prefix-instead-of-show-toplevel-for-fin.patch")
sha256sums=('c85b6b46d0edd40d2301038cdea96bb6adc14d62ef943e75afb08b3e7bcf142a'
            '3567297ac59d2e400ebacc639c482947b625b558044d7fb7642b0a8550a40fb0')

prepare() {
  cd "${srcdir}/${_realname/-/_}-${pkgver}"
  patch -Np1 -i "${srcdir}/0001-git-Use-show-prefix-instead-of-show-toplevel-for-fin.patch"
  
  cd "${srcdir}"
  rm -rf python-build-${CARCH} | true
  cp -r "${_realname/-/_}-${pkgver}" "python-build-${CARCH}"
}

build() {
  msg "Python build for ${CARCH}"  
  cd "${srcdir}/python-build-${CARCH}"
  ${MINGW_PREFIX}/bin/python setup.py build
}

package() {
  cd "${srcdir}/python-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build
}
